﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Reflection;

namespace MessageServer.utilities
{
    public class Properties
    {
        Hashtable _props;

        public Properties()
        {
            _props = new Hashtable();
        }

        public void loadproperties()
        {
        }

        public void setProperty(String prop, object value)
        {
            _props[prop] = value;
        }

        public object getProperty(String prop)
        {
            return _props[prop];
        }

        public int getIntProperty(String prop)
        {
            if (_props.ContainsKey(prop))
                return System.Convert.ToInt32(_props[prop]);

            return -1; //possibly this needs to be different, an exception
        }

        public void injectprops(Object obj)
        {
            Type objtype = obj.GetType();
            foreach (DictionaryEntry d in _props)
            {
                PropertyInfo propinfo = objtype.GetProperty(System.Convert.ToString(d.Key));
                Console.WriteLine("Trying to set property: " + d.Key + " Got: " + propinfo);
                if (propinfo != null)
                    propinfo.SetValue(obj, d.Value, null);
            }
        }
    }
}
